#define BOOST_TEST_MODULE testElementUser

#include <boost/test/unit_test.hpp>

#include "common/elements/element_maker.h"
#include "common/elements/user.h"

BOOST_AUTO_TEST_CASE(testUserJson)
{
    Elements::UserPtr first = std::make_shared<Elements::User>();
    first->setId(1);
    first->setLogin("a");
    first->setFirstName("b");
    first->setMiddleName("c");
    first->setLastName("d");
    first->setEmail("e");
    first->setPasswordHash("f");
    first->setNeedChangePassword(true);
    first->setIsBlocked(true);
    first->setUiLang("ru");

    const auto json = first->toJsonString();
    const Elements::ElementPtr second(Elements::fromJsonString(json));
    BOOST_CHECK(first->isSame(second.get()));

    const auto third = std::static_pointer_cast<Elements::User>(second);
    BOOST_CHECK(1 == third->id());
    BOOST_CHECK("a" == third->login());
    BOOST_CHECK("b" == third->firstName());
    BOOST_CHECK("c" == third->middleName());
    BOOST_CHECK("d" == third->lastName());
    BOOST_CHECK("e" == third->email());
    BOOST_CHECK("f" == third->passwordHash());
    BOOST_CHECK(true == third->needChangePassword());
    BOOST_CHECK(true == third->isBlocked());
    BOOST_CHECK("ru" == third->uiLang());

    first->setPassword(R"(LQvDqf'6n9_zOr\L[?jYy )d)");
    BOOST_CHECK(first->checkPassword(R"(LQvDqf'6n9_zOr\L[?jYy )d)"));

    first->setPassword(R"(i&_R0 !icNal5~b]oVzC^:?H)");
    BOOST_CHECK(first->checkPassword(R"(i&_R0 !icNal5~b]oVzC^:?H)"));

    first->setPassword(R"(:[G_\f?\u#>hK>cf$ SF;P2:]uRxc+)");
    BOOST_CHECK(first->checkPassword(R"(:[G_\f?\u#>hK>cf$ SF;P2:]uRxc+)"));
}
